home *** CD-ROM | disk | FTP | other *** search
/ The Amiga Classic Collection / The Amiga Classic Collection - Disc 1.iso / Business / BU11-AddressMgr.DMS / BU11-AddressMgr.adf / programming_tips_code / amiga.c < prev    next >
C/C++ Source or Header  |  1994-07-08  |  5KB  |  250 lines

  1. /* ----------------------------------------------------------------- */
  2.  
  3. /* amiga.c - intuition code */
  4.  
  5. #include "amiga.h"
  6.  
  7. UBYTE AmigaProg(void)
  8.  
  9. {           
  10.  
  11. UBYTE error_number=NO_ERROR; 
  12.                          
  13. ULONG port_mask;
  14.  
  15. struct Message *message_p;
  16.  
  17. SetRast(g_rastport_p,BLUE);
  18.  
  19. RefreshWindowFrame(g_window_p);
  20.  
  21. WriteBoxText(&intuitext1,XPOS1,LINEPOS1,MESSAGE0,BLUE,OFFSET); 
  22.  
  23.   
  24. ActivateWindow(g_window_p);
  25.  
  26. port_mask=(1<<g_window_p->UserPort->mp_SigBit);
  27.  
  28. do { 
  29.  
  30.     Wait(port_mask); 
  31.  
  32.                 
  33.     while (message_p=(struct Message *)GT_GetIMsg(g_window_p->UserPort))
  34.  
  35.             {
  36.             
  37.             error_number=IntuitionEvent((struct IntuiMessage *)message_p);
  38.  
  39.             }
  40.  
  41.    }while(error_number!=PROGRAM_EXIT);
  42.  
  43. return(error_number);
  44.  
  45. }
  46.  
  47. /* ----------------------------------------------------------------- */
  48.  
  49. UBYTE IntuitionEvent(struct IntuiMessage *message_p)
  50.  
  51. {
  52.  
  53. UBYTE error_number=NO_ERROR;
  54.                            
  55. UWORD code; 
  56.  
  57. ULONG class;
  58.  
  59. class=message_p->Class; 
  60.             
  61. code= message_p->Code;
  62.  
  63.  
  64. GT_ReplyIMsg(message_p);
  65.  
  66. switch (class) {
  67.  
  68.                 case IDCMP_CLOSEWINDOW: 
  69.                              
  70.                 error_number=PROGRAM_EXIT; break;
  71.  
  72.  
  73.                 case IDCMP_ACTIVEWINDOW:
  74.                 
  75.                 WindowToFront(g_window_p);
  76.                
  77.                 break;
  78.                 
  79.  
  80.                 case IDCMP_INACTIVEWINDOW:
  81.                                
  82.                 break;
  83.   
  84.   
  85.                 case IDCMP_MENUPICK: 
  86.                              
  87.                 error_number=MenuEvent(code);
  88.                 
  89.                 break;
  90.                              
  91.                                                                  
  92.                 default: error_number=PROGRAM_EXIT; 
  93.  
  94.                 break;
  95.  
  96.               }
  97.               
  98. return(error_number);
  99.  
  100. }
  101.  
  102. /* ----------------------------------------------------------------- */
  103.  
  104. UBYTE MenuEvent(UWORD code)
  105.  
  106. {
  107.  
  108. UBYTE error_number=NO_ERROR;  
  109.  
  110. UWORD menu_number, item_number, i;
  111.  
  112. if (code!=MENUNULL)
  113.  
  114.   {
  115.                     
  116.   menu_number=MENUNUM(code);
  117.                             
  118.   item_number=ITEMNUM(code);
  119.        
  120.   OffMenu(g_window_p,SHIFTMENU(0)|SHIFTITEM(NOITEM));
  121.  
  122.   OffMenu(g_window_p,SHIFTMENU(1)|SHIFTITEM(NOITEM));
  123.  
  124.  
  125.   switch(menu_number) 
  126.  
  127.    {
  128.     
  129.     case 0:    error_number=PROGRAM_EXIT; break;
  130.                
  131.  
  132.     case 1:    for(i=0;i<4;i++) 
  133.         
  134.                 { 
  135.  
  136.                  WriteBoxText(&intuitext1,
  137.                  XPOS1,LINEPOS1,message[i],GREY,OFFSET); 
  138.                        
  139.                  SetTimer(0,(item_number+1)*666666);
  140.                 
  141.                 }
  142.  
  143.                WriteBoxText(&intuitext1,
  144.                XPOS1,LINEPOS1,MESSAGE0,BLUE,OFFSET); 
  145.      
  146.                break;
  147.  
  148.        
  149.     default:   break;
  150.  
  151.    } 
  152.  
  153.   OnMenu(g_window_p,SHIFTMENU(1)|SHIFTITEM(NOITEM));
  154.      
  155.   OnMenu(g_window_p,SHIFTMENU(0)|SHIFTITEM(NOITEM));
  156.  
  157.   }
  158.  
  159. return(error_number);
  160. }
  161.  
  162. /* ----------------------------------------------------------------- */
  163.  
  164.  
  165. void __regargs SetTimer(ULONG seconds, ULONG microseconds)
  166.  
  167. {
  168.  
  169. g_timer_request_p->tr_time.tv_secs=seconds;
  170.  
  171. g_timer_request_p->tr_time.tv_micro=microseconds;
  172.  
  173. DoIO((struct IORequest *)g_timer_request_p);
  174.  
  175. }
  176.  
  177. /* ----------------------------------------------------------------------- */
  178.  
  179.  
  180.  
  181.  
  182. void WriteBoxText(struct IntuiText *itext_p, WORD x, WORD y, UBYTE *text_p, UBYTE colour, UBYTE offset)
  183.  
  184. {
  185.  
  186. LONG length;
  187.  
  188. LONG height;
  189.  
  190. height=g_window_p->IFont->tf_YSize;
  191.           
  192. itext_p->IText=text_p;
  193.  
  194. itext_p->LeftEdge=x;
  195.  
  196. itext_p->TopEdge=y;
  197.  
  198. length=IntuiTextLength(itext_p);
  199.  
  200. if (length) {
  201.  
  202.             SetAPen(g_rastport_p,colour);
  203.            
  204.             RectFill(g_rastport_p,
  205.                      itext_p->LeftEdge-offset,
  206.                      itext_p->TopEdge-offset,
  207.                      itext_p->LeftEdge+length+offset,
  208.                      itext_p->TopEdge+height+offset);
  209.               
  210.              DrawBevelBox(g_rastport_p,
  211.                           itext_p->LeftEdge-offset,itext_p->TopEdge-offset,
  212.                           length+2*offset,height+2*offset,
  213.                           GT_VisualInfo, g_visual_info_p,
  214.                           GTBB_Recessed, TRUE,
  215.                           TAG_DONE);
  216.              
  217.              PrintIText(g_rastport_p,itext_p,0,0);
  218.  
  219.    
  220.             }
  221.          
  222. }
  223.  
  224. /* ----------------------------------------------------------------- */
  225.  
  226. void ClearBoxText(struct IntuiText *itext_p, UBYTE colour, UBYTE offset)
  227.  
  228. {        
  229.  
  230. LONG length, height;
  231.  
  232. height=g_window_p->IFont->tf_YSize;
  233.  
  234. length=IntuiTextLength(itext_p);
  235.  
  236. if (length) {
  237.         
  238.             SetAPen(g_rastport_p,colour);
  239.            
  240.             RectFill(g_rastport_p,
  241.                      itext_p->LeftEdge-offset,
  242.                      itext_p->TopEdge-offset,
  243.                      itext_p->LeftEdge+length+offset,
  244.                      itext_p->TopEdge+height+offset);
  245.             }
  246.                          
  247. }
  248.  
  249. /* ----------------------------------------------------------------- */
  250.